package com.tianyu.jty.system.task;

import com.jswzc.jiuling.service.order.DlServiceI;
import com.jswzc.jiuling.service.order.TzServiceI;
import com.tianyu.jty.system.entity.ScheduleJob;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时任务工作类 大连 每天执行
 * @author ty
 * @date 2015年1月13日
 */
@DisallowConcurrentExecution
@Component("MonthTz")
public class MonthTz implements Job {

    private TzServiceI tzService;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        try {
            ClassPathXmlApplicationContext contexts;
            contexts = new ClassPathXmlApplicationContext("classpath*:/applicationContext-dubbo.xml");
            contexts.start();
            tzService = (TzServiceI) contexts.getBean("tzService"); // 获取远程服务代理
            //每月9.19.29会员日抽奖
            tzService.showApplyRecord();
            System.out.println("tz每月9.19.29会员日抽奖"+tzService.showApplyRecord());

            ScheduleJob scheduleJob = (ScheduleJob) context.getMergedJobDataMap().get("scheduleJob");
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
            System.out.println("任务名称 = [" + scheduleJob.getName() + "]" + " 在 " + dateFormat.format(new Date()) + " 时运行");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
